<form action="${ctx}/platManager/hqAgentForm" method="post" id="addForm" >
	<input type="hidden" name="id" value="${plat.id!}" />
	<div class="form-group form-inline row">
		<div class="col-sm-6">
			<label><span style="color: red">*</span>名称：</label>
			<input class="form-control" type="text" name="nickName" value="${plat.nickName!}" maxlength="25" required />
		</div>
		<div class="col-sm-6">
			<label><span style="color: red">*</span>登录名：</label>
			<input class="form-control" type="text" name="loginName" value="${plat.loginName!}" maxlength="25" required />
		</div>
	</div>
	<div class="form-group form-inline row">
		<div class="col-sm-6">
			<label><span style="color: red">*</span>联系电话：</label>
			<input class="form-control" type="text" name="phone" maxlength="12" value="${plat.phone!}" required />
		</div>
		<div class="col-sm-6">
			<label>是否启用：</label>
			<#if plat.state??>
				<label class="radio-inline"><input type="radio" class="minimal" name="state"  value="100" <#if plat.state = 100>checked</#if> >&nbsp;&nbsp;启用</label>
				<label class="radio-inline"><input type="radio" class="minimal" name="state"  value="200" <#if plat.state = 200>checked</#if> >&nbsp;&nbsp;禁用</label>
			<#else>
				<label class="radio-inline"><input type="radio" class="minimal" name="state"  value="100" checked >&nbsp;&nbsp;启用</label>
				<label class="radio-inline"><input type="radio" class="minimal" name="state"  value="200" >&nbsp;&nbsp;禁用</label>
			</#if>
		</div>
	</div>
	<div class="form-group form-inline row">
		<div class="col-sm-6 col-select179-box">
			<label>区域：</label>
			<select class="form-control select2" name="agentRegion">
				<option value="">--请选择--</option>
				<#list agentRegions as r>
					<option value="${r.toString()!}" <#if plat.agentRegion?? && plat.agentRegion.toString() == r.toString()>selected</#if> >${r.getName()!}</option>
				</#list>
			</select>
		</div>
		<div class="col-sm-6 col-select179-box">
			<label><span style="color: red">*</span>部门：</label>
			<select class="form-control select2" name="groupId">
				<option value="">--请选择--</option>
				<#list platGroupList as pg>
					<option value="${pg.groupId}" <#if myPlatGroupIdSet?? && myPlatGroupIdSet?seq_contains(pg.groupId)>selected</#if> >${pg.groupName}</option>
				</#list>
			</select>
		</div>
	</div>
	<div class="form-group form-inline row">
		<div class="col-sm-6 col-select179-box">
			<label>客户经理：</label>
			<select class="form-control select2" name="accountManagerId">
				<option value="-1">--请选择--</option>
				<#list accountManages as accountManage>
					<option value="${accountManage.id!}" <#if plat.accountManagerId?? && plat.accountManagerId == accountManage.id>selected</#if> >${accountManage.nickName!}</option>
				</#list>
			</select>
			<input class="form-control" type="hidden" name="accountManagerName" />
		</div>
		<div class="col-sm-6 col-select179-box">
			<label>销售：</label>
			<select class="form-control select2" name="agentSaleId">
				<option value="">--请选择--</option>
				<#list saleManagers as sale>
					<option value="${sale.id!}" <#if plat.agentSaleId?? && plat.agentSaleId == sale.id>selected</#if> >${sale.nickName!}</option>
				</#list>
			</select>
			<input class="form-control" type="hidden" name="agentSaleName" />
		</div>
	</div>
	
</form>

<script>
	$('.select2').select2();
	$.fn.modal.Constructor.prototype.enforceFocus = function() {};
	
	//iCheck for checkbox and radio inputs
    $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
      checkboxClass: 'icheckbox_minimal-blue',
      radioClass   : 'iradio_minimal-blue'
    });
	
	$("#addForm").validate({
        rules: {
            loginName : {
            	trimRequired : true,
            	unContainSpace : true,
            	verifyLoginNameUnique : true
            }
        },
        messages: {
        }
	});
	$.validator.addMethod("trimRequired", function(value, element) {
		if (value == '') {
			return false;
		}
		if ($.trim(value) == '') {
			return false;
		}
		return true;
	}, "该字段不能为空");
	$.validator.addMethod("unContainSpace", function(value, element) {
		if (value == '' || $.trim(value) == '') {
			return true;
		}
		if ($.trim(value).search(/\s/) != -1) {
			return false;
		}
		return true;
	}, "该字段不能包含空格");
	// 验证登录名唯一。返回true验证通过， 返回false验证不通过 
	$.validator.addMethod("verifyLoginNameUnique", function(value, element) {
		var id = $(":input[name='id']").val();
		
		var verificationPassed = false;
		$.ajax({
			url : "${ctx}/platManager/verifyLoginNameUnique",
			type : 'post',
			dataType : 'json',
			async : false,
			data : {"id" : id, "loginName" : value},
			success : function(data) {
				if (data.result == 'success') {
					verificationPassed = true;
				}
			}
		});
		
		return verificationPassed;
	}, "登录名不能为重复");
	$("select[name='agentSaleId']").change(function() {
		var saleName = $(this).find("option:selected").text();
		$("input[name='agentSaleName']").val(saleName);
	});
	
	$("select[name='accountManagerId']").change(function() {
		var accountManagerName = $(this).find("option:selected").text();
		$("input[name='accountManagerName']").val(accountManagerName);
	});
	
</script>